<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        function throttle(fn, delay) {
            let isRun = false;
            return function(...args) {
                if(isRun) return;
                isRun = true;
                setTimeout(() => {
                    fn.apply(this, args);
                    isRun = false;
                })
            }
        }
    </script>
    <script>
        // 毕竟setTimeout计时的准确性跟主线程的繁忙程度相关，所以这里我们使用毫秒计时。
        function throttle(fn, delay) {
            let lastRunTime = 0;
            return function (...args) {
                const currentTime = new Date().getTime();
                if(currentTime - lastRunTime >= delay) {
                    fn.apply(this, args);
                    lastRunTime = currentTime;
                }
            }
        }
        const test = (...args) => {
            console.log(args);
        }
        const throttleTest = throttle(test, 3000);
        setInterval(() => {
            throttleTest(1, 2, 3, 4);
        }, 1000);
    </script>
</body>
</html>